package com.shengzai.hbase;

import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.hbase.TableName;
import org.apache.hadoop.hbase.client.*;
import org.apache.hadoop.hbase.util.Bytes;

import java.io.IOException;

public class GetData {
    public static void main(String[] args) throws IOException {
        Configuration conf = new Configuration();
        conf.set("hbase.zookeeper.quorum","master,node1,node2");
        Connection connection = ConnectionFactory.createConnection(conf);

        TableName tableName = TableName.valueOf("api_test:api_student");
        Table table = connection.getTable(tableName);
        //key
        Get gets = new Get("1810404125".getBytes());
        //key对应的数据对象
        Result result = table.get(gets);

        String rowKey = Bytes.toString(result.getRow());

        String age = Bytes.toString(result.getValue("students_info".getBytes(), "age".getBytes()));

        String score = Bytes.toString(result.getValue("students_score".getBytes(), "score".getBytes()));

        System.out.println(rowKey+"\t"+age+"\t"+score);
        table.close();
        connection.close();

    }
}
